<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>App更新</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="__LAYUIADMIN__/res/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__LAYUIADMIN__/res/adminui/dist/css/admin.css" media="all">
    <style>
        .preview-container {
            position: relative;
            display: inline-block;
            margin: 10px 0;
        }

        .preview-container .layui-icon-close {
            position: absolute;
            right: 0;
            top: 0;
            background-color: rgba(0, 0, 0, 0.5);
            color: #fff;
            font-size: 16px;
            width: 20px;
            height: 20px;
            line-height: 20px;
            text-align: center;
            border-radius: 50%;
            cursor: pointer;
            z-index: 10;
        }

        .layui-upload-img {
            border: 1px solid #e6e6e6;
            padding: 2px;
        }

        .admin-container {
            padding: 20px;
        }

        .layui-tab-content {
            padding: 20px 0;
        }

        .layui-form-item {
            margin-bottom: 25px;
        }

        .layui-upload-img {
            width: 100px;
            height: 100px;
            margin: 10px;
        }

        .layui-upload-list img {
            max-width: 300px;
            max-height: 200px;
        }

        .update-history-item {
            margin-bottom: 20px;
            padding: 15px;
            border: 1px solid #e6e6e6;
            border-radius: 5px;
            position: relative;
        }

        .update-history-item .remove-update {
            position: absolute;
            right: 10px;
            top: 10px;
        }

        .preview-item {
            display: inline-block;
            position: relative;
            margin-right: 10px;
            margin-bottom: 10px;
        }

        .preview-item img {
            width: 200px;
            height: 125px;
            object-fit: cover;
            border-radius: 5px;
        }

        .preview-item .remove-preview {
            position: absolute;
            right: 5px;
            top: 5px;
            background-color: rgba(0, 0, 0, 0.5);
            color: #fff;
            width: 20px;
            height: 20px;
            line-height: 20px;
            text-align: center;
            border-radius: 50%;
            cursor: pointer;
        }

        .app-info-container {
            border: 1px solid hsl(0, 0%, 90%);
            border-radius: 5px;
            padding: 15px;
            margin-bottom: 20px;
        }
    </style>
</head>

<body>

    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">App基本配置</div>
                    <div class="layui-card-body">
                        <form class="layui-form" lay-filter="">
                            <!-- 基本信息 -->
                            <fieldset class="layui-elem-field">
                                <legend>基本信息</legend>
                                <div class="layui-field-box">
                                    <!-- 位置1：在基本信息旁边添加按钮 -->
                                    <div class="layui-card-header">
                                        App基本配置
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">应用名称</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="appName" value="{$data.appName}"
                                                placeholder="请输入应用名称" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">应用副标题</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="appSubtitle" value="{$data.appSubtitle}"
                                                placeholder="请输入应用副标题" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">应用图标</label>
                                        <div class="layui-input-block">
                                            <div class="layui-upload">
                                                <button type="button" class="layui-btn"
                                                    id="app-icon-upload">上传图标</button>
                                                <div class="layui-upload-list">
                                                    <div class="preview-container"
                                                        style="position: relative; display: inline-block;">
                                                        <img class="layui-upload-img" id="app-icon-preview"
                                                            src="{$data.appIcon}">
                                                        <input type="hidden" name="appIcon" id="app-icon-input"
                                                            value="{$data.appIcon}">
                                                        <i class="layui-icon layui-icon-close" id="app-icon-delete"
                                                            style="position: absolute; right: 0; top: 0; background-color: rgba(0,0,0,0.5); color: #fff; font-size: 16px; width: 20px; height: 20px; line-height: 20px; text-align: center; border-radius: 50%; cursor: pointer; display: none;"></i>
                                                    </div>
                                                    <p id="app-icon-text"></p>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">版本号</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="appVersion" value="{$data.appVersion}"
                                                placeholder="例如: 1.0.0" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">应用大小</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="appSize" value="{$data.appSize}" placeholder="大小"
                                                autocomplete="off" class="layui-input">
                                        </div>
                                        <div class="layui-form-mid">MB</div>
                                    </div>

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">系统要求</label>
                                        <div class="layui-input-inline">
                                            <select name="appSupportOS">
                                                <option value="Android 4.4+" {$data.appSupportOS=='Android 4.4+'
                                                    ? 'selected' : '' }>Android 4.4+</option>
                                                <option value="Android 5.0+" {$data.appSupportOS=='Android 5.0+'
                                                    ? 'selected' : '' }>Android 5.0+</option>
                                                <option value="Android 6.0+" {$data.appSupportOS=='Android 6.0+'
                                                    ? 'selected' : '' }>Android 6.0+</option>
                                                <option value="Android 7.0+" {$data.appSupportOS=='Android 7.0+'
                                                    ? 'selected' : '' }>Android 7.0+</option>
                                                <option value="Android 8.0+" {$data.appSupportOS=='Android 8.0+'
                                                    ? 'selected' : '' }>Android 8.0+</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </fieldset>
                            <!-- 应用描述 -->
                            <fieldset class="layui-elem-field">
                                <legend>应用描述</legend>
                                <div class="layui-field-box">
                                    <div class="layui-form-item layui-form-text">
                                        <label class="layui-form-label">应用简介</label>
                                        <div class="layui-input-block">
                                            <textarea name="appDescription" placeholder="请输入应用描述" class="layui-textarea"
                                                rows="6">{$data.appDescription}</textarea>
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">描述标题</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="descTitle" value="{$data.descTitle}"
                                                placeholder="描述标题" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                            </fieldset>
                            <!-- 开发者选项 -->
                            <fieldset class="layui-elem-field">
                                <legend>开发者信息</legend>
                                <div class="layui-field-box">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">开发者</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="developer" value="{$data.developer}"
                                                placeholder="开发者名称" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">发布日期</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="releaseDate" id="releaseDate"
                                                value="{$data.releaseDate}" placeholder="YYYY-MM-DD" autocomplete="off"
                                                class="layui-input">
                                        </div>
                                    </div>
                                </div>
                            </fieldset>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="demo2">确认保存</button>
                                    <button type="button" class="layui-btn layui-btn-normal"
                                        id="update-history-btn2">更新历史</button>
                                    <button type="button" class="layui-btn layui-btn-warm"
                                        id="publish-settings-btn2">发布设置</button>
                                </div>
                            </div>
                        </form>
                    </div>

                </div>
            </div>

        </div>
    </div>
    </div>

    <script src="__LAYUI__/layui.js"></script>
    <script>
        layui.use(function () {
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var table = layui.table;
            var upload = layui.upload;
            $ = layui.$;
            // 日期选择器
            laydate.render({
                elem: '#releaseDate'
            });

            // 应用图标上传
            upload.render({
                elem: '#app-icon-upload',
                url: '/admin/system/uploadImg',
                field: 'images', // 修改提交字段为images
                done: function (res) {
                    // 上传完毕回调
                    $('#app-icon-preview').attr('src', res.data);
                    $('#app-icon-input').val(res.data); // 保存图片URL到隐藏input中
                    $('#app-icon-delete').show(); // 显示删除按钮
                    layer.msg('上传成功');
                },
                error: function () {
                    // 请求异常回调
                    layer.msg('上传失败');
                }
            });

            // 删除图标
            $('#app-icon-delete').on('click', function () {
                $('#app-icon-preview').attr('src', '');
                $('#app-icon-input').val(''); // 清空隐藏input中的值
                $(this).hide(); // 隐藏删除按钮
                layer.msg('图标已删除');
            });

            // 检查是否有图标
            $(document).ready(function () {
                console.log($('#app-icon-input'));

                if ($('#app-icon-input').val()) {
                    $('#app-icon-delete').show();
                }
            });
            // 更新历史按钮点击事件
            $('#update-history-btn, #update-history-btn2').on('click', function () {
                layer.open({
                    type: 2,
                    title: '更新历史记录',
                    area: ['80%', '80%'],
                    content: '/admin/app/appUpgrade'
                });
            });

            // 发布设置按钮点击事件
            $('#publish-settings-btn, #publish-settings-btn2').on('click', function () {
                layer.open({
                    type: 2,
                    title: '发布设置',
                    area: ['80%', '80%'],
                    content: '/admin/app/appDownload',
                });
            });
            form.on('submit(demo2)', function (data) {
                var field = data.field; // 获取表单字段值
                $.post('/admin/app/update/?conf=app_base', field, (res) => {
                    if (res.code == 200) {
                        layer.msg('保存成功')
                    } else {
                        layer.msg(res.msg)
                    }
                })
                return false;
            });
        });


    </script>
</body>

</html>